// pages/personnal/myOrder/myOrder.js
const app = getApp();
const util = require("../../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: 0,
    orderList: []
  },

  /**
   * 查看物流
   */
  ckwl:function(event){
    let orderId = event.currentTarget.dataset.orderId
    wx.navigateTo({
      url: '/pages/personnal/seeWuLiu/seeWuLiu?orderId=' + orderId,
    })
    
  },

  /**
   * 确认收货
   */
  qrsh: function (event){
    let that = this
    let orderId = event.currentTarget.dataset.orderId
    wx.showModal({
      title: '提示',
      content: '确认收货吗？',
      success: function (res) {
        if (res.cancel) {
          //点击取消,默认隐藏弹框
        } else {
          //点击确定
          let getTitleDetailUrl = app.globalData.baseUrl + "sureReceive"
          let data = {
            orderId: orderId
          }
          util.requestLoading(getTitleDetailUrl, data, "GET").then(res => {
            // console.log(res)
            if (res.data.status==0){
              wx.showToast({
                title: '确认成功',
                icon: 'success',
                duration: 2000
              });
            }else{
              wx.showToast({
                title: '确认失败',
                icon: 'loading',
                duration: 2000
              });
            }
            getTitleDetailUrl = app.globalData.baseUrl + "activityList"
            data = {
              cid: wx.getStorageSync('cid')
            }
            util.requestLoading(getTitleDetailUrl, data, "GET").then(res => {
              app.globalData.orderList = res.data.orderList
              that.setData({
                orderList: res.data.orderList
              })
            })
          })
        }
      }
    })
    
  },

  /**
   * 类型选择 
   */
  changeType:function(event){
    let that = this
    // console.log(event)
    let type = event.currentTarget.dataset.type
    this.setData({
      type: type
    })
    // console.log(that.data.type)
    // if(type == 0) {
      
    // }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    //获取订单列表
    let activityListUrl = app.globalData.baseUrl + "activityList"
    let data = {
      cid: wx.getStorageSync("cid")
    }
    util.requestLoading(activityListUrl, data, "GET").then(res => {
      // console.log(res)
      // console.log(res.data.orderList)
      that.setData({
        orderList: res.data.orderList,
        type: 0
      })
    })
    // console.log(that.data.orderList)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})